<template>
  <view class="content" v-if="is_show">
    <view class="top">
      <view class="bet" style="margin-bottom: 20rpx">
        <view class="max-text" style="font-size: 40rpx">{{
          workDetail.title
        }}</view>
        <view class="text-color" style="font-size: 32rpx; font-weight: 600">
          {{ workDetail.xname }}
        </view>
      </view>
      <view class="flex box" style="margin-bottom: 20rpx">
        <view class="bet">
          <!-- <image style="width: 18rpx" src="../../static/tab2/map.png" alt="" /> -->
          <span class="min-text" style="font-size: 28rpx">
            年龄：{{workDetail.start_age}}-{{workDetail.end_age}}
          </span>
        </view>
        <view class="bet">
          <image src="../../static/tab2/xueli.png" alt="" />
          <span class="min-text" style="font-size: 28rpx">{{
            workDetail.ename
          }}</span>
        </view>
        <view class="bet">
          <image src="../../static/tab2/jingyan.png" alt="" />
          <span class="min-text" style="font-size: 28rpx">{{
            workDetail.wname
          }}</span>
        </view>
		
      </view>
      <view class="bet">
        <view class="flex wrap">
          <view
            v-for="item in workDetail.fulilabels"
            :key="item.id"
            style="margin-bottom: 20rpx"
          >
            <y-tag :text="item.name" bgcolors="#efefef" color="#000000"></y-tag>
          </view>
        </view>
        <view
          v-if="type == 'qiuzhi' && workDetail.fulilabels !== undefined && workDetail.fulilabels.length < 4"
          class="min-text"
        > 
          发布时间：{{ workDetail.create_time }}
        </view>
      </view>
      <view
        v-if="type == 'qiuzhi' && workDetail.fulilabels !== undefined && workDetail.fulilabels.length > 3"
        class="min-text"
      >
        发布时间：{{ workDetail.create_time }}
      </view>
    </view>
    <view class="boxItem flex" v-if="type == 'qiuzhi'">
      <view class="headImg">
        <image :src="workDetail.uavatar" alt="" />
      </view>
      <view>
        <view class="max-text" style="margin-bottom: 20rpx">
          {{ workDetail.uname }}
        </view>
        <view class="z-text flex" style="color: #8e8e93; font-weight: 300">
          <u-icon name="phone-fill" color="#B7B7B7" size="14"></u-icon>
          {{ workDetail.phone }}
        </view>
        <view class="z-text flex" style="color: #8e8e93; font-weight: 300">
          <u-icon name="map-fill" color="#B7B7B7" size="14"></u-icon>
          {{ workDetail.address[0] }} {{ workDetail.address[1]? workDetail.address[1]:'' }}
          {{ workDetail.address[2]?workDetail.address[2]:'' }}
        </view>
      </view>
    </view>
    <view class="boxItem">
      <view class="max-text" style="margin-bottom: 20rpx">{{
        type == "qiuzhi" ? "技能描述" : "职位描述"
      }}</view>
      <view
        v-if="workDetail.content"
        class="z-text"
        style="color: #8e8e93; font-weight: 300"
      >
        <view v-if="type == 'zhaopin'" v-html="workDetail.content"></view>
        <view v-else>
          <p v-for="item in workDetail.content.split(/；|;/)">
            {{ item == 'undefined' ? "未填写" :item }}
          </p>
        </view>
      </view>
    </view>
    <view class="boxItem flex" v-if="type == 'zhaopin'">
      <view class="headImg">
        <image
          :src="pic + (workDetail.clogo || '/assets/img/avatar.png')"
          alt=""
        />
      </view>
      <view>
        <view class="max-text" style="margin-bottom: 20rpx">
          {{ workDetail.cname }}
        </view>
        <view class="z-text" style="color: #8e8e93; font-weight: 300">
          姓名：{{ workDetail.username }}
        </view>
      </view>
	  
    </view>
	<view class="margin_top">
		<view class="" v-if="workDetail.images">
			<image :src="item" v-for="(item,index) in workDetail.images_text" :key="index" @click="lbtpriview(index,workDetail.images_text)" style="width: 100%;" class="radius" mode="widthFix"></image>
		</view>
	</view>
	
	<!-- type:qiuzhi求职，zhaopin招聘 -->
	<!-- group_id：3文员 -->
	<!-- 文员不显示电话沟通聊一聊 -->
	<!-- 求职不判断是否文员直接全部展示 -->
	<view class="flexcenter" v-if="group_id!=3 && group_id!=2">
		<button
		  v-if="type == 'zhaopin'"
		  @click="makePhoneCall"
		  class="button goutong "
		>
		  电话沟通
		</button>
	</view>
    <view class="flexcenter" v-if="(type=='zhaopin' && group_id!=3 && group_id!=2) || type=='qiuzhi'">
    	<button v-if="workDetail.user_id!=user_id" @click="sixin()" class="button goutong ">
    	  聊一聊
    	</button>
    </view>
  </view>
</template>

<script>
import yTag from "@/components/y-tag/index";
const httpRequest = require("@/common/httpRequest.js")
export default {
  name: "tab-1",
  components: {
    yTag,
  },
  data() {
    return {
      pic: this.$IMG_URL,
      type: "",
      id: "",
      workDetail: {},
	  is_show:false,
	  user_id:"",
	  group_id:""
    };
  },
  onLoad(e) {
	  this.group_id = uni.getStorageSync("group_id")
    this.type = e.type; // type qiuzhi 求职
    this.id = e.id;
    uni.setNavigationBarTitle({
      title: this.type == "qiuzhi" ? "求职详情" : "招聘详情",
    });
    this.getworkDetail();
	this.user_id = uni.getStorageSync("user_id")
  },
  methods: {
	  sixin() {
	  	if (this.workDetail.user_id == this.user_id) { //如果当前主页的id是自己的话不走下面逻辑
	  		return false
	  	}
	  	let that = this
	  	uni.showLoading({
	  		mask:true,
	  		title:"请稍后"
	  	})
	  	httpRequest.request('/api/user/addFriends', 'GET', {
	  		firend_id:this.workDetail.user_id
	  	}).then(res => {
	  		uni.hideLoading()
			if(res.code==1){
				let data = {
					firend_id: this.workDetail.user_id,
					friend_name: this.workDetail.uname,
					firend_avatar_text: this.workDetail.uavatar
				}
				uni.navigateTo({
					url: "/pages/tab5/chat?msg=" + encodeURIComponent(JSON.stringify(data))
				})
			}
	  	})
	  	
	  },
    makePhoneCall() {
	
      uni.makePhoneCall({
        phoneNumber: this.workDetail.phone_num,
      });
    },
    getworkDetail() {
		let _this=this;
      this.http
        .get(this.type == "qiuzhi" ? "work/detail" : "recruit/detail", {
          id: this.id,
        })
        .then((res) => {
          this.workDetail = res.data;
		  console.log('===---=-=-==-',this.workDetail);
          if (this.type == "qiuzhi") {
            this.workDetail.address = this.workDetail.address.split(/\/|，|,/);
          } else {
            // this.workDetail.address = this.workDetail.address.split("/");
            this.workDetail.title = this.workDetail.name;
          }
		  _this.is_show=true;
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.top {
  background-color: #ffffff;
  padding: 20rpx 30rpx;
}
.box {
  view {
    margin-right: 50rpx;
    image {
      height: 24rpx;
      width: 24rpx;
      margin-right: 10rpx;
    }
  }
}
.headImg {
  width: 100rpx;
  height: 100rpx;
  margin-right: 30rpx;
  image {
    border-radius: 50rpx;
    width: 100%;
    height: 100%;
  }
}
.goutong {
  margin-top: 100rpx;
  width: 80%;
  border-radius: 50rpx;
}
</style>